home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_0799 / 518 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  1.8 KB

  1. From: inf2gr04@informatik.uni-frankfurt.de
  2. Posted-Date: Mon, 4 Oct 93 8:34:57 MEZ
  3. Received-Date: Mon, 4 Oct 93 08:35:00 +0100
  4. Message-Id: <9310040735.AA13950@hptest.rbi.informatik.uni-frankfurt.de>
  5. Subject: sleep() and device drivers ...
  6. To: mint@atari.archive.umich.edu
  7. Date: Mon, 4 Oct 93 8:34:57 MEZ
  8. Mailer: Elm [revision: 70.85]
  9.  
  10.  
  11. A question:
  12.  
  13. Is there a safe way for a device driver function to decide whether a call to
  14. sleep() was interrupted by delivery of a signal, or (even better) a way to
  15. make sure the functions arguments are still valid after a sleep()?
  16.  
  17. To understand why this is important, look at a piece of code from pipe_write():
  18. (Read first (1), then (2))
  19.  
  20.     if (nbytes > 0 && nbytes <= PIPE_BUF) {
  21. check_atomicity:
  22.         r = p->tail - p->head;
  23. /* (2)
  24.  * Here we dereference p, which is a pointer to one of the fifos pipes.
  25.  * Because we might get here after sleep() (see (2)), *p's memory could
  26.  * have been freed and we are in trouble!
  27.  */
  28.         if (r < 0) r += PIPESIZ;
  29.         r = (PIPESIZ-1) - r;
  30.         if (r < nbytes) {
  31.             if (p->readers == 0 || p->readers == VIRGIN_PIPE) {
  32.                 check_sigs();
  33.                 DEBUG(("pipe_write: broken pipe"));
  34.                 raise(SIGPIPE);
  35.                 return EPIPE;
  36.             }
  37.             if (p->rsel) {
  38.                 wakeselect(p->rsel);
  39.                 p->rsel = 0;
  40.             }
  41.             wake(IO_Q, (long)p);
  42.             sleep(IO_Q, (long)p);
  43. /* (1)
  44.  * Woken up from sleep(). Because sleep() has an embedded call of check_sigs()
  45.  * in it, a signal handler function could just have Fclose()'d all references
  46.  * to the fifo. Because then there are no more readers/writers, pipe_close()
  47.  * kfree()'s all the fifo's memory.
  48.  */
  49.             goto check_atomicity;
  50.         }
  51.     }
  52.  
  53.  
  54. Unixes check for delivery of signals in such situations and return EINTR
  55. if appropriate or restart the whole system call if possible.
  56.  
  57. I'd be grateful for any suggestions.
  58.  
  59. -- kay roemer.
  60.  
  61.